package com.yunquan.ohana.ui.calendar.event.week.dialog

import android.content.Context
import android.view.Gravity
import android.view.View
import com.yunquan.ohana.R
import com.yunquan.ohana.base.dialog.BaseDialog
import com.yunquan.ohana.databinding.DialogBottomDeleteBinding
import com.yunquan.ohana.utils.setOnClickListener

class BottomDeleteDialog(context: Context) : BaseDialog<DialogBottomDeleteBinding>(context) {
    private var title = ""
    private var tip = ""
    private var onCancelClick: (() -> Unit)? = null
    private var onDeleteClick: ((dialog: BottomDeleteDialog) -> Unit)? = null
    override fun createViewBinding(): DialogBottomDeleteBinding =
        DialogBottomDeleteBinding.inflate(layoutInflater)

    override fun cancelable(): Boolean = false

    override fun setGravity(): Int = Gravity.BOTTOM

    override fun setAnimRes(): Int = R.style.BottomAnimStyle

    override fun initData() = Unit

    override fun initView() {
        binding.tvTitle.text = title
        binding.tvTip.text = tip
        setOnClickListener(this, binding.tvCancel, binding.tvDelete)
    }

    override fun onClick(view: View?) {
        when (view) {
            binding.tvCancel -> {
                dismiss()
                onCancelClick?.invoke()
            }

            binding.tvDelete -> {
                dismiss()
                onDeleteClick?.invoke(this)
            }
        }
    }

    fun setTitle(title: String) {
        this.title = title
    }

    fun setTip(tip: String) {
        this.tip = tip
    }

    fun setOnCancelClick(onCancelClick: () -> Unit) {
        this.onCancelClick = onCancelClick
    }

    fun setOnDeleteClick(onDeleteClick: (dialog: BottomDeleteDialog) -> Unit) {
        this.onDeleteClick = onDeleteClick
    }
}